package com.mob.tools.utils;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.Set;

public class SQLiteHelper
{
  public static void close(SingleTableDB paramSingleTableDB)
  {
    paramSingleTableDB.close();
  }

  public static int delete(SingleTableDB paramSingleTableDB, String paramString, String[] paramArrayOfString)
    throws Throwable
  {
    paramSingleTableDB.open();
    return paramSingleTableDB.db.delete(paramSingleTableDB.getName(), paramString, paramArrayOfString);
  }

  public static void execSQL(SingleTableDB paramSingleTableDB, String paramString)
    throws Throwable
  {
    paramSingleTableDB.open();
    paramSingleTableDB.db.beginTransaction();
    try
    {
      paramSingleTableDB.db.execSQL(paramString);
      paramSingleTableDB.db.setTransactionSuccessful();
      return;
    }
    catch (Throwable localThrowable)
    {
      throw localThrowable;
    }
    finally
    {
      paramSingleTableDB.db.endTransaction();
    }
  }

  public static SingleTableDB getDatabase(Context paramContext, String paramString)
  {
    return getDatabase(paramContext.getDatabasePath(paramString).getPath(), paramString);
  }

  public static SingleTableDB getDatabase(String paramString1, String paramString2)
  {
    return new SingleTableDB(paramString1, paramString2, null);
  }

  public static int getSize(SingleTableDB paramSingleTableDB)
    throws Throwable
  {
    paramSingleTableDB.open();
    Cursor localCursor = null;
    try
    {
      localCursor = paramSingleTableDB.db.rawQuery("select count(*) from " + paramSingleTableDB.getName(), null);
      boolean bool = localCursor.moveToNext();
      int i = 0;
      if (bool)
      {
        int j = localCursor.getInt(0);
        i = j;
      }
      return i;
    }
    catch (Throwable localThrowable)
    {
      throw localThrowable;
    }
    finally
    {
      localCursor.close();
    }
  }

  public static long insert(SingleTableDB paramSingleTableDB, ContentValues paramContentValues)
    throws Throwable
  {
    paramSingleTableDB.open();
    return paramSingleTableDB.db.replace(paramSingleTableDB.getName(), null, paramContentValues);
  }

  public static Cursor query(SingleTableDB paramSingleTableDB, String[] paramArrayOfString1, String paramString1, String[] paramArrayOfString2, String paramString2)
    throws Throwable
  {
    paramSingleTableDB.open();
    return paramSingleTableDB.db.query(paramSingleTableDB.getName(), paramArrayOfString1, paramString1, paramArrayOfString2, null, null, paramString2);
  }

  public static Cursor rawQuery(SingleTableDB paramSingleTableDB, String paramString, String[] paramArrayOfString)
    throws Throwable
  {
    paramSingleTableDB.open();
    return paramSingleTableDB.db.rawQuery(paramString, paramArrayOfString);
  }

  public static int update(SingleTableDB paramSingleTableDB, ContentValues paramContentValues, String paramString, String[] paramArrayOfString)
    throws Throwable
  {
    paramSingleTableDB.open();
    return paramSingleTableDB.db.update(paramSingleTableDB.getName(), paramContentValues, paramString, paramArrayOfString);
  }

  public static class SingleTableDB
  {
    private SQLiteDatabase db;
    private HashMap<String, Boolean> fieldLimits;
    private LinkedHashMap<String, String> fieldTypes;
    private String name;
    private String path;
    private String primary;
    private boolean primaryAutoincrement;

    private SingleTableDB(String paramString1, String paramString2)
    {
      this.path = paramString1;
      this.name = paramString2;
      this.fieldTypes = new LinkedHashMap();
      this.fieldLimits = new HashMap();
    }

    private void close()
    {
      if (this.db != null)
      {
        this.db.close();
        this.db = null;
      }
    }

    private String getName()
    {
      return this.name;
    }

    private void open()
    {
      if (this.db == null)
      {
        this.db = SQLiteDatabase.openOrCreateDatabase(new File(this.path), null);
        String str1 = "select count(*) from sqlite_master where type ='table' and name ='" + this.name + "' ";
        Cursor localCursor = this.db.rawQuery(str1, null);
        int i = 1;
        if (localCursor != null)
        {
          if ((localCursor.moveToNext()) && (localCursor.getInt(0) > 0))
            i = 0;
          localCursor.close();
        }
        if (i != 0)
        {
          StringBuilder localStringBuilder = new StringBuilder();
          localStringBuilder.append("create table  ").append(this.name).append("(");
          Iterator localIterator = this.fieldTypes.entrySet().iterator();
          if (localIterator.hasNext())
          {
            Map.Entry localEntry = (Map.Entry)localIterator.next();
            String str2 = (String)localEntry.getKey();
            String str3 = (String)localEntry.getValue();
            boolean bool1 = ((Boolean)this.fieldLimits.get(str2)).booleanValue();
            boolean bool2 = str2.equals(this.primary);
            boolean bool3;
            label229: String str4;
            label256: String str5;
            if (bool2)
            {
              bool3 = this.primaryAutoincrement;
              localStringBuilder.append(str2).append(" ").append(str3);
              if (!bool1)
                break label307;
              str4 = " not null";
              localStringBuilder.append(str4);
              if (!bool2)
                break label314;
              str5 = " primary key";
              label273: localStringBuilder.append(str5);
              if (!bool3)
                break label321;
            }
            label307: label314: label321: for (String str6 = " autoincrement,"; ; str6 = ",")
            {
              localStringBuilder.append(str6);
              break;
              bool3 = false;
              break label229;
              str4 = "";
              break label256;
              str5 = "";
              break label273;
            }
          }
          localStringBuilder.replace(-1 + localStringBuilder.length(), localStringBuilder.length(), ");");
          this.db.execSQL(localStringBuilder.toString());
        }
      }
    }

    public void addField(String paramString1, String paramString2, boolean paramBoolean)
    {
      if (this.db == null)
      {
        this.fieldTypes.put(paramString1, paramString2);
        this.fieldLimits.put(paramString1, Boolean.valueOf(paramBoolean));
      }
    }

    public void setPrimary(String paramString, boolean paramBoolean)
    {
      this.primary = paramString;
      this.primaryAutoincrement = paramBoolean;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.tools.utils.SQLiteHelper
 * JD-Core Version:    0.6.2
 */